package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.GroupNoticeSigns;
import cn.stylefeng.guns.sys.modular.system.mapper.GroupNoticeSignsMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.GroupNoticeSignsParam;
import cn.stylefeng.guns.sys.modular.system.model.params.UserParam;
import cn.stylefeng.guns.sys.modular.system.model.result.GroupNoticeDeptResult;
import cn.stylefeng.guns.sys.modular.system.model.result.GroupNoticeSignsResult;
import cn.stylefeng.guns.sys.modular.system.service.GroupNoticeSignsService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 群通知署名表 服务实现类
 * </p>
 *
 * @author jiangge
 * @since 2021-07-26
 */
@Service
public class GroupNoticeSignsServiceImpl extends ServiceImpl<GroupNoticeSignsMapper, GroupNoticeSigns> implements GroupNoticeSignsService {

    @Override
    public void add(GroupNoticeSignsParam param) {
        GroupNoticeSigns entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(GroupNoticeSignsParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(GroupNoticeSignsParam param) {
        GroupNoticeSigns oldEntity = getOldEntity(param);
        GroupNoticeSigns newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public GroupNoticeSignsResult findBySpec(GroupNoticeSignsParam param) {
        return null;
    }

    @Override
    public List<GroupNoticeSignsResult> findListBySpec(GroupNoticeSignsParam param) {
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(GroupNoticeSignsParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public String getOneSign() {
        String result = this.baseMapper.getOneSign();
        return result;
    }

    @Override
    public List<GroupNoticeDeptResult> getDeptList(UserParam param) {
        List<GroupNoticeDeptResult> list = this.baseMapper.getDeptList(param);
        return list;
    }

    private Serializable getKey(GroupNoticeSignsParam param) {
        return param.getSignId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private GroupNoticeSigns getOldEntity(GroupNoticeSignsParam param) {
        return this.getById(getKey(param));
    }

    private GroupNoticeSigns getEntity(GroupNoticeSignsParam param) {
        GroupNoticeSigns entity = new GroupNoticeSigns();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
